*This script calculates the Sweat Index sw over an area, given the fields:
*relative humidity (rhprs %), temperature (tmpprs K), wind (ugrdprs; vgrdprs m/s)
*Written by Laura Bertolani and Massimo Bollasina - March 2001

'set lev 850'
'define part1=(112+0.9*(tmpprs-273.15))*pow((rhprs/100),0.125)'
'define td850=part1-112+0.1*(tmpprs-273.15)'
'define t850=tmpprs(lev=850)-273.15'
'define u850=ugrdprs(lev=850)'
'define v850=vgrdprs(lev=850)'
'define t500=tmpprs(lev=500)-273.15'
'define dir850=180+atan2(u850,v850)*180/3.14159'
'set lev 500'
'define u500=ugrdprs(lev=500)'
'define v500=vgrdprs(lev=500)'
'define dir500=180+atan2(u500,v500)*180/3.14159'
'define deltafi=dir500-dir850'
'define termine1=12*maskout(td850,td850)'
'define termine1b=const(termine1,0.0,-u)'
'define termi=td850+t850-2*t500'
'define termi2=20*(termi-49)'
'define termine2=maskout(termi2,termi2)'
'define termine2b=const(termine2,0.0,-u)'
'define effe8=2*1.942*sqrt(u850*u850+v850*v850)'
'define termine3=maskout(effe8,effe8)'
'define termine3b=const(termine3,0.0,-u)'
'define effe5=1.942*sqrt(u500*u500+v500*v500)'
'define termine4=maskout(effe5,effe5)'
'define termine4b=const(termine4,0.0,-u)'
'define esse=sin(deltafi*3.14159/180)'
'define termi5=125*(esse+0.2)'
'define a=maskout(dir850,130-dir850)'
'define one1=const(const(a,1),0,-u)'
'define a=maskout(dir850,dir850-250)'
'define one1b=const(const(a,1),0,-u)'
'define a=maskout(dir500,210-dir500)'
'define one2=const(const(a,1),0,-u)'
'define a=maskout(dir500,dir500-310)'
'define one2b=const(const(a,1),0,-u)'
'define a=maskout(deltafi,-deltafi)'
'define one3=const(const(a,1),0,-u)'
'define a=maskout(effe8,15-effe8)'
'define one4=const(const(a,1),0,-u)'
'define b=maskout(effe5,15-effe5)'
'define one5=const(const(b,1),0,-u)'
'define termin5=termi5*(1-one1)*(1-one2)*(1-one3)*(1-one4)*(1-one5)*(1-one1b)*(1-one2b)'
'define termine5=maskout(termin5,termin5)'
'define termine5b=const(termine5,0.0,-u)'
'define sw=termine1b+termine2b+termine3b+termine4b+termine5b'
'd sw'